package com.itqf.factory;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.FactoryBean;

import java.io.InputStream;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/9/28
 * @Time: 下午2:40
 */
public class MySqlSessionFactoryBean implements FactoryBean<SqlSessionFactory> {

   public MySqlSessionFactoryBean(){
        System.out.println("MySqlSessionFactoryBean......");
    }

    @Override
    public SqlSessionFactory getObject() throws Exception {
        System.out.println("MySqlSessionFactoryBean-----getObject ...........");

        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        InputStream inputStream =  Resources.getResourceAsStream("mybatisConfig.xml");

        SqlSessionFactory sqlSessionFactory =   sqlSessionFactoryBuilder.build(inputStream);//mybatis的配置文件

        return sqlSessionFactory;
    }

    @Override
    public Class<?> getObjectType() {
        return SqlSessionFactory.class;
    }

    @Override
    public boolean isSingleton() {//是否单例
        return true;
    }




}
